# coding:utf-8
import unittest

from api.employee import EmployeeAPI
from api.login import LoginAPI
from utils import common_assert


class TestEmployeeAPI(unittest.TestCase):
    token=None
    staff_id=None
    def setUp(self) -> None:
        self.login_api=LoginAPI()
        self.staff_api=EmployeeAPI()
    def tearDown(self) -> None:
        pass
    def test01_login(self):
        login_data={"mobile":13800000002,"password":123456}
        response=self.login_api.login(login_data)
        print(response.json())
        common_assert(self,response,200,True,10000,'操作成功')
        TestEmployeeAPI.token="Bearer "+response.json().get('data')

    def test02_insert_staff(self):
        staff_info={"username":"spfsofng","mobile":"19373770200","workNumber":"B08070090"}
        response=self.staff_api.insert_e(staff_info,TestEmployeeAPI.token)
        print(response.json())
        common_assert(self,response,200,True,10000,'操作成功')
        TestEmployeeAPI.staff_id=response.json().get('data').get('id')

    def test03_select_staff(self):
        response=self.staff_api.select_e(TestEmployeeAPI.staff_id,TestEmployeeAPI.token)
        print(response.json())
        common_assert(self,response,200,True,10000,'操作成功')

    def test04_update_staff(self):
        response=self.staff_api.update_e(TestEmployeeAPI.staff_id,TestEmployeeAPI.token,{'username':"Bella"})
        print(response.json())
        common_assert(self,response,200,True,10000,'操作成功')

    def test05_selet_staff(self):
        response = self.staff_api.select_e(TestEmployeeAPI.staff_id, TestEmployeeAPI.token)
        print(response.json())
        common_assert(self,response,200,True,10000,'操作成功')

    def test06_delete_staff(self):
        response=self.staff_api.delete_e(TestEmployeeAPI.staff_id,TestEmployeeAPI.token)
        print(response.json())
        common_assert(self,response,200,True,10000,'操作成功')